
import ocsf.client.*;
import java.io.*;


public class ClientHandler extends ObservableClient{
	ClientIF clientUI;
	
	public ClientHandler(String host, int port, ClientIF clientUI) throws IOException {
		super(host, port); //Call the superclass constructor
		this.clientUI = clientUI;
		openConnection();
	}

	@Override
	protected void handleMessageFromServer(Object msg) {
		clientUI.displayMsg(msg.toString());
	}

	public void handleMessageFromClientUI(String message){
		try{
	    	sendToServer(message);
	    }
	    catch(IOException e){
	      clientUI.displayMsg("Could not send message to server.  Terminating client.");
	      quit();
	    }
	}
	
	public void quit(){
		try{
	      closeConnection();
	    }
	    catch(IOException e) {}
	    System.exit(0);
	}
}